﻿#ifndef _STREAM_FIFOBUFF_H_
#define _STREAM_FIFOBUFF_H_

#include "fifo_buf.h"
#include <map>
#include "frame_utility.h"

typedef struct _FRAME_CRT_ADDR_ 
{
	uchar_t * pHead;

	bool      bDeviHead;
	uchar_t * pHeadFragment;
	uint32_t  fragmentSz;

	uchar_t * pBody;
	uint32_t  bodySize;
	
	uchar_t * pTail;
	uint32_t  tailSize;

	uint32_t  dataPos;
	uint32_t  frameSize;
	bool      bStart;
}FRAME_CRT_ADDR;

typedef struct _FRAME_GET_ADDR_
{
	bool bGotBufAddr;
	uchar_t * pBufAddr;   
	uint32_t  frameSize; //整帧视频的长度
	uchar_t * pBaseBuf;
	bool      bConsume;	//是否已经消费掉,如果是给出内存地址的,会先保留不消费,待下次取数据时去消费掉
}FRMAE_GET_ADDR;

class CReplayFrmBuf:public CFIFO_buf
{
public:
	CReplayFrmBuf();
	~CReplayFrmBuf();
public:
	int		Open(int ch, int bufSize);
	int		PutFrame(uchar_t * buf, uint32_t frameLen);
	int     GetFrame(uchar_t * buf, uint32_t frameLen,bool bPeek = true);
	int     GetAVIFrame(uchar_t * buf, uint32_t frameLen,bool bPeek = true);
	int     GetFrameNoneHead(uchar_t * buf, uint32_t frameLen);
	uint8_t GetNextFrameType();
	int     GetNextFrmSize();
	int64_t GetNextFrmTime();
	int     GetFrmBuf(FRAME_CRT_ADDR & frmAddr,uint32_t frmHeadSize,uint32_t frmSize);
protected:
	int     m_channel;
	int     m_frameNO;
	int64_t m_nextFrmTm;
	CFrmUtility   m_frmTool;
	LHN_FRAME_H * m_pFrm;
static const int FRAME_H_LEN = BASE_FRAME_HEAD_LEN;
};

#endif  //_STREAM_FIFOBUFF_H_